package practises;

public class Num3 {
    public ListNode middleNode(ListNode head) {
//        ListNode slow = head;
//        ListNode fast = head;
//        while(fast != null && fast.next != null) {
//            slow = slow.next;
//            fast = fast.next.next;
//        }
//        return slow;
        ListNode cur = head;
        int count = 0;
        while(cur != null) {
            count++;
            cur = cur.next;
        }
        count /= 2;
        cur = head;
        while(count != 0) {
            cur = cur.next;
            count--;
        }
        return cur;
    }
}
